package utils

import (
	"bytes"
	"encoding/binary"
	"strconv"
	"strings"
)

func BytesToNumber[T Number](data []byte) (t T) {
	if len(data) == 0 {
		return 0
	}

	buf := bytes.NewBuffer(data)
	binary.Read(buf, binary.BigEndian, &t)
	return
}

func BytesToString(data []byte, number bool) string {
	if len(data) == 0 {
		return ""
	}

	tmp := make([]string, len(data))
	for _, v := range data {
		if number && v == 0 {
			continue
		}

		tmp = append(tmp, strconv.Itoa(int(v)))
	}
	return strings.Join(tmp, "")
}
